
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="../style.css" type="text/css" />
</head>
<?php
		include_once "../inc/docroot.php";
		include_once PATH."inc/class.autores.inc.php";
		$autores = new autores($db);
		if(isset($_GET['mail']))$mail = $_GET['mail'];
		if(isset($_GET['subject']))$subject = $_GET['subject'];
		if(isset($_GET['edit']))$edit = $_GET['edit'];
		if(isset($_GET['delete']))$delete = $_GET['delete'];
?>

<body>
<div>
  

<div class="autores_header">
	  
	  
	  <?php
           if(  !empty($_POST['filter']) && isset($edit) && $edit == 1) {
        	echo "<br /><br />";
			if(isset($mail))echo $autores->editfilter("mail");
			if(isset($subject))echo $autores->editfilter("subject");
			?>
			<script>
			window.opener.location.reload();
			//window.close();
            </script>
            <?php
	   }
	   else if(isset($delete) && $delete == 1) {
        	echo "<br /><br />";
			if(isset($mail))echo $autores->deletefilter("mail");
			if(isset($subject))echo $autores->deletefilter("subject");
			?>
			<script>
			window.opener.location.reload();
			window.close();
            </script>
            <?php
	   }
	   else if( !empty($_POST['filter'])) {
        	echo "<br /><br />";
			if(isset($mail))echo $autores->addfilter("mail");
			if(isset($subject))echo $autores->addfilter("subject");
			?>
			<script>
			window.opener.location.reload();
            </script>
            <?php
	   }
	   else {
    		echo "<br />";
    		echo "<br />";
    		if(!isset($delete))
		    echo "<label>Please fill all the fields.</label>";
	    }
		echo "<br />";
		echo "<br />";
	   
		if((isset($subject)||isset($mail)) && isset($edit) && $edit == 0){
			if(isset($mail)) echo "<label> EDIT FILTER:" .$mail."</label>";
			if(isset($subject)) echo "<label> EDIT FILTER:" .$subject."</label>";
		}
		else if(isset($mail) && isset($delete) && $delete == 0){
		    echo "<label> Are you sure to DELETE MAIL FILTER: " .$mail."</label>";
		    echo "<br/>";
		    echo "<br/>";
		    ?>
		      <form method="post" action="addnewfilter.php<?php if(isset($mail)) echo "?mail=".$mail;?><?php if(isset($subject)) echo "?subject=".$subject;?><?php if(isset($delete)) echo "&delete=1";?>" name="deletefilterform" id="deletefilterform">
		      <br /><br />
		      <input type="submit" name="deletefilter" id="deletefilter" value="DELETE MAIL FILTER" class="btn btn--blue btn--m" />
		    <?php
		}
		else {
			if(isset($mail)) echo "<label> ADD A MAIL ID FILTER</label>";
			if(isset($subject)) echo "<label> ADD A SUBJECT FILTER</label>";
		}
		
?>
  </div>  
  
  <?php if(!isset($delete)){ ?>
  
  <form method="post" action="addnewfilter.php<?php if(isset($mail)) echo "?mail=".$mail;?><?php if(isset($subject)) echo "?subject=".$subject;?><?php if(isset($edit)) echo "&edit=1";?>" name="addfilterform" id="addfilterform">
    <div style="font-size:9px;" align="center">
      <br />
      <br />
      <input type="text" name="filter" id="filter" style="text-align:center"/>
      <label for="filter">Filter</label>
      <br />
      <br />
      <br />
      <br />
      <input type="submit" name="addfilterinput" id="addfilterinput" value="Save filter" class="btn btn--blue btn--m" />
    </div>
  </form>
<?php } ?>

  
</div>
</body>
</html>